<table cellspacing="1" cellpadding="3" style="background: #fff;width:100%">
<tr>
    <td class="aslefttd">Blank of 1st</td>
    <td><input type="text" class="input4" id="b_1" <?php if ($ans) { echo 'value="'.$ans['answer']['b_1'].'"';}?>></td>			    
</tr>
<tr>
    <td class="aslefttd">Blank of 2nd</td>
    <td><input type="text" class="input4" id="b_2" <?php if ($ans) { echo 'value="'.$ans['answer']['b_2'].'"';}?>></td>			    
</tr>
<tr>
    <td class="aslefttd">Blank of 3rd</td>
    <td><input type="text" class="input4" id="b_3" <?php if ($ans) { echo 'value="'.$ans['answer']['b_3'].'"';}?>></td>			    
</tr>
<tr>
    <td class="aslefttd">Blank of 4th</td>
    <td><input type="text" class="input4" id="b_4" <?php if ($ans) { echo 'value="'.$ans['answer']['b_4'].'"';}?>></td>			    
</tr>
<tr>
    <td class="aslefttd">Blank of 5th</td>
    <td><input type="text" class="input4" id="b_5" <?php if ($ans) { echo 'value="'.$ans['answer']['b_5'].'"';}?>></td>			    
</tr>
<tr>
    <td class="aslefttd">Blank of 6th</td>
    <td><input type="text" class="input4" id="b_6" <?php if ($ans) { echo 'value="'.$ans['answer']['b_6'].'"';}?>></td>			    
</tr>
</table>
<script type="text/javascript">
(function($){    
    <?php 
    $i=0;
    if ($ans){
	    foreach ($ans['answer'] as $v){
	    	if ($v!=''){
	    		$i++;
	    	}
	    }
    }
    if ($i){
    	echo 'bnums = '.$i.';';
    }else {
    	echo 'bnums=0;';
    }?>
	$.fn.insertRoundCaret = function (tagName) {
		
        if(bnums==6){
            alert('at most fill '+bnums+' blanks');
            return false;
        }
        bnums++;
		return this.each(function(){
			strStart = '['+tagName+']';
			strEnd = '[/'+tagName+']';
			if (document.selection) {
				//IE support
				stringBefore = this.value;
				this.focus();
				sel = document.selection.createRange();
				insertstring = sel.text;
				fullinsertstring = strStart + sel.text + strEnd;
				sel.text = fullinsertstring;
				document.selection.empty();
				this.focus();
				stringAfter = this.value;
				i = stringAfter.lastIndexOf(fullinsertstring);
				range = this.createTextRange();
				numlines = stringBefore.substring(0,i).split("\n").length;
				i = i+3-numlines+tagName.length;
				j = insertstring.length;
				range.move("character",i);
				range.moveEnd("character",j);
				range.select();
			}else if (this.selectionStart || this.selectionStart == '0') {
				//MOZILLA/NETSCAPE support
				startPos = this.selectionStart;
				endPos = this.selectionEnd;
				scrollTop = this.scrollTop;
				this.value = this.value.substring(0, startPos) + strStart + this.value.substring(startPos,endPos) + strEnd + this.value.substring(endPos,this.value.length);
				this.focus();
				this.selectionStart = startPos + strStart.length ;
				this.selectionEnd = endPos + strStart.length;
				this.scrollTop = scrollTop;
			} else {
				this.value += strStart + strEnd;
				this.focus();
			}
		});
	};
	})(jQuery)


function getAnswer()
{
    tmpNum=0;
    var b_1 = $.trim($("#b_1").val());
    var b_2 = $.trim($("#b_2").val());
    var b_3 = $.trim($("#b_3").val());
    var b_4 = $.trim($("#b_4").val());
    var b_5 = $.trim($("#b_5").val());
    var b_6 = $.trim($("#b_6").val());
    if (bnums==0){
    	alert('At least set one blank in question');
        return false;
    }
    if(b_1) tmpNum=1;
    if(b_2) tmpNum=2;
    if(b_3) tmpNum=3;
    if(b_4) tmpNum=4;
    if(b_5) tmpNum=5;
    if(b_6) tmpNum=6;
    if(bnums!=tmpNum){
        alert('The blank in question  is not match the blank of answers');
    	return false;
    }
    var tmpobj = {"res":null,"answer":{"b_1":b_1,"b_2":b_2,"b_3":b_3,"b_4":b_4,"b_5":b_5,"b_6":b_6}};
    return $.toJSON(tmpobj);
}
$("#addblank").fadeIn();
$("#addblank").fadeOut('fast');
$("#addblank").fadeIn();
</script>
